package com.jierui.meter.frontend.base.enums;

import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Getter;

import java.util.Objects;

/**
 * @create 2018-05-17 10:09
 **/
@Getter
@JsonFormat(shape = JsonFormat.Shape.OBJECT)
public enum Channel {

    IOS_APP_STORE(1, "IOS_App_Store", 1),
    BAIDU(2, "baidu", 2),
    C360(3, "c360", 2),
    QQ(4, "qq", 2),
    OPPO(5, "oppo", 2),
    VIVO(6, "vivo", 2),
    HUAWEI(7, "huawei", 2),
    MI(8, "mi", 2),
    MEIZU(9, "meizu", 2),
    LENOVO(10, "lenovo", 2),
    SAMSUNG(11, "samsung", 2),
    WANDOUJIA(12,"wandoujia", 2),
    WEB(13,"web", 2), 
    C91(14, "c91", 2),
    ANZHUO(15, "anzhuo", 2),
    GOOGLE(16, "google", 2),
    BAIDUASST(17, "baiduasst", 2),  
    ;
    private Integer code;
    private String value;
    private Integer type;

    Channel(Integer code, String value,Integer type) {

        this.code = code;
        this.value = value;
        this.type = type;
    }



	public static Channel get(String channelName) {

		if (Objects.isNull(channelName)) {
			return null;
		}
		Channel[] enums = values();
		for (Channel anEnum : enums) {
			if (Objects.equals(anEnum.value, channelName)) {
				return anEnum;
			}
		}
		return null;
	}

    public static Channel get(Integer channelId) {

        if (Objects.isNull(channelId)) {
            return null;
        }
        Channel[] enums = values();
        for (Channel anEnum : enums) {
            if (Objects.equals(anEnum.code, channelId)) {
                return anEnum;
            }
        }
        return null;
    }

    public static Channel[] getByType(Integer type) {
        if (type.equals(IOS_APP_STORE.type))
            return getOs();
        else if(type.equals(BAIDU.type)) {
            return getAndroid();
        }
        return null;
    }

    public static Channel[] getOs(){
        return new Channel[]{IOS_APP_STORE};
    }
    public static Channel[] getAndroid(){
        return new Channel[]{BAIDU,C360,QQ,OPPO,VIVO,HUAWEI,MI,MEIZU,LENOVO,SAMSUNG,WANDOUJIA,WEB,C91,ANZHUO,GOOGLE,BAIDUASST};
    }
}
